package com.dis.insurance.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.insurance.service.MedicalCardService;
import com.dis.pojo.dto.MedicalCardDTO;
import com.dis.pojo.queryDTO.MedicalCardPageQueryDTO;
import com.dis.pojo.vo.MedicalCardVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/medical-card")
@Api(tags = "医疗卡管理")
@Slf4j
public class MedicalCardController {

    @Autowired
    private MedicalCardService medicalCardService;

    @PostMapping
    @ApiOperation("新增医疗卡")
    @CheckPermission("medical:card:add")
    public Result save(@RequestBody MedicalCardDTO medicalCardDTO) {
        medicalCardService.save(medicalCardDTO);
        return Result.success();
    }

    @GetMapping("/page/data")
    @ApiOperation("分页查询医疗卡")
    @CheckPermission("medical:card:query:data")
    public Result<PageResult> pageData(MedicalCardPageQueryDTO medicalCardPageQueryDTO) {
        PageResult pageResult = medicalCardService.pageQuery(medicalCardPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询医疗卡")
    @CheckPermission("medical:card:query")
    public Result<PageResult> page(MedicalCardPageQueryDTO medicalCardPageQueryDTO) {
        PageResult pageResult = medicalCardService.pageQuery(medicalCardPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询医疗卡")
    @CheckPermission("medical:card:query")
    public Result<MedicalCardVO> getById(@PathVariable Long id) {
        MedicalCardVO medicalCardVO = medicalCardService.getById(id);
        return Result.success(medicalCardVO);
    }

    @PutMapping
    @ApiOperation("更新医疗卡")
    @CheckPermission("medical:card:edit")
    public Result update(@RequestBody MedicalCardDTO medicalCardDTO) {
        medicalCardService.update(medicalCardDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除医疗卡")
    @CheckPermission("medical:card:delete")
    public Result delete(@PathVariable Long id) {
        medicalCardService.deleteById(id);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用医疗卡")
    @CheckPermission("medical:card:edit")
    public Result changeStatus(@PathVariable Integer status, Long id) {
        medicalCardService.changeStatus(id, status);
        return Result.success();
    }
    /**
     * 根据病人ID查询病人的所有医疗卡
     */
    @GetMapping("/insure/{insureId}")
    @ApiOperation("根据病人ID查询病人的所有医疗卡")
    @CheckPermission("medical:card:query")
    public Result getByInsureId(@PathVariable Long insureId) {
        List<MedicalCardVO> medicalCardVO = medicalCardService.getByInsureId(insureId);
        return Result.success(medicalCardVO);
    }
}